#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL r[maxn],g[maxn],b[maxn];
LL tot1,tot2,tot3;
multiset<LL>p1,p2,p3;
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL n;cin>>n;
    for(LL i=1;i<=n*2;i++){
        char col;
        LL val;
        cin>>val>>col;
        if(col=='R') r[++tot1]=val;
        if(col=='G') g[++tot2]=val;
        if(col=='B') b[++tot3]=val;
    }
    if((tot1%2==0)&&(tot2%2==0)&&(tot3%2==0)){
        cout<<"0"<<"\n";
        return 0;
    }
    bool flag=1;LL ou=0;
    if(tot1&1){
        flag=0;
        for(LL i=1;i<=tot1;i++){
            ///p1[++cnt1]=r[i];
            p1.insert(r[i]);
        }
    }
    if(flag==0){
        if(tot2&1){
            for(LL i=1;i<=tot2;i++){
                ///p2[++cnt2]=g[i];
                p2.insert(g[i]);
            }
            ou=tot3;
            for(LL i=1;i<=ou;i++){
                ///p3[++cnt3]=b[i];
                p3.insert(b[i]);
            }
        }
        else{
            for(LL i=1;i<=tot3;i++){
                ///p2[++cnt2]=b[i];
                p2.insert(b[i]);
            }
            ou=tot2;
            for(LL i=1;i<=ou;i++){
                ///p3[++cnt3]=g[i];
                p3.insert(g[i]);
            }
        }
    }
    else{
        ou=tot1;
        for(LL i=1;i<=tot2;i++){
            ///p1[++cnt1]=g[i];
            p1.insert(g[i]);
        }
        for(LL i=1;i<=tot3;i++){
            ///p2[++cnt2]=b[i];
            p2.insert(b[i]);
        }
        for(LL i=1;i<=ou;i++){
            ///p3[++cnt3]=r[i];
            p3.insert(r[i]);
        }
    }
    LL ans=1e18;
    LL temp1=1e19;LL temp2=1e18;
    for(LL i=1;i<=cnt;){

        multiset<LL>::iterator it1;
        multiset<LL>::iterator it2;
        it1=p1.lower_bound(i);
        it2=p1.lower_bound(i);
        if(it1==p1.end()) it1--;
        if(it2!=p1.begin()) it2--;

        LL temp1=min(abs(i-(*it1)),abs(i-(*it2)));
    }
    for(LL i=1;i<=cnt1;i++){
        LL x=p1[i];
        multiset<LL>::iterator it1,it2;
        it1=p2.lower_bound(x);
        it2=p2.lower_bound(x);
        if(it1==p2.end()) it1--;
        if(it2!=p2.begin()) it2--;

        LL temp=min(abs(x-(*it1)),abs(x-(*it2)));

        ans=min(ans,temp);
    }

    cout<<ans<<"\n";
   	return 0;
}
